// pages/product/pro-detail.js
var wxParse = require('../../vendor/wxParser/index')
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        image: []
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData(options)
        this.loadData()
    },
    returnHome() {
        wx.switchTab({
            url: '/pages/home2/home',
        })
    },
    loadData() {
        wx.showLoading({
            title: '加载中...',
        })
        app.http.get('index/product-detail', {
            data: {
                id: this.data.id
            }
        }).then(res => {
            this.setData({
                image: res.data.photo,
                info: res.data
            })
            this.setData({
                companyId: res.data.company_id
            })
            wxParse.parse({
                bind: 'richText',
                html: res.data.intr,
                target: this,
                enablePreviewImage: false,
            });
            wx.setNavigationBarTitle({
                title: res.data.name,
            })
            wx.hideLoading()
        }).catch(err => {
            wx.wxToast.error(err.message)
        })
    },
    //调用微信内置地图 
    openLocation() {
        wx.chooseAddress({
            success: res => {
                var obj = {
                    name: res.userName,
                    phone: res.telNumber,
                    address: res.provinceName + res.cityName + res.countyName + res.detailInfo
                }
                this.setData(obj)
            },
            fail: err => {

            }
        })
    },
    bindReturn() {
        wx.navigateBack()
    },
    call() {
        wx.makePhoneCall({
            phoneNumber: this.data.info.company.mobile,
        })
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
            title: this.data.info.name,
            path: '/pages/product/pro-detail?id=' + this.data.info.id,
            success: function (res) {
                // 转发成功
            },
            fail: function (res) {
                // 转发失败
            }
        }
    }
})